import net from '@/network/net.js';
import $ from 'jquery';
import store from '@/store/store.js';

let api = {
    'getQiNiuToken': '/app/file/v1/getQINIUToken',
    'uploadImage': '/app/file/v1/uploadImage',
    'getVCode': '/app/file/v1/getVCode'
};

let postCfg = {
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    transformRequest: function(data) {
        return $.param(data)
    }
}

let res = {

};

function getQiNiuToken() {
    let p = new Promise(function(resolve, reject) {
        net.req.post(api.getQiNiuToken, {
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}

function uploadImage() {
    let p = new Promise(function(resolve, reject) {
        net.req.post(api.uploadImage, {
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}

function getVCode(w,h) {
    let p = new Promise(function(resolve, reject) {
        net.req.post(api.getVCode, {
            w: w,
            h: h
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}

export default {
    getQiNiuToken,
    uploadImage,
    getVCode,
}
